#include "Enemy.h"
#include "Vista.h"
#include "MainCharacter.h"
#include "Bullet.h"
#include "Weapon.h"
#include "ShootEmUp.h"
#include "GameManager.h"

#define NBTOUCH 100

using namespace Ogre;
using namespace std;



Vista::Vista()
{
	type = VISTA;
	initialize();
	initNbTouch();
}

void Vista::initNbTouch(){
	nbTouch = NBTOUCH;
}

void Vista::initialize()
{
	mDirection = Vector3::ZERO;

	mEntity = mSceneMgr->createEntity(getName(), "vista.mesh");
	mEntity->setUserObject( this );
	

	mSceneNode = mSceneMgr->getSceneNode(Enemy::DEFAULT_NODE_NAME)->createChildSceneNode(Enemy::DEFAULT_NODE_NAME+string("_")+getName());
	Vector3 initialPosition( 
		Math::RangeRandom(ShootEmUp::WORLD_MIN.x, ShootEmUp::WORLD_MAX.x), 
		Math::RangeRandom(ShootEmUp::WORLD_MIN.y, ShootEmUp::WORLD_MAX.y), 
		ShootEmUp::WORLD_MAX.z + 150
		);
	mSceneNode->setPosition( initialPosition );
	mSceneNode->scale(0.3, 0.3, 0.3);
	if ( mEntity->isAttached() )
		mEntity->getParentSceneNode()->detachObject( mEntity );
	mSceneNode->attachObject( mEntity );
	mDistance = 0;
}

bool Vista::move()
{

	if(mDistance < 0){

		mDestination = Vector3(Math::RangeRandom(ShootEmUp::WORLD_MIN.x, ShootEmUp::WORLD_MAX.x),0,ShootEmUp::WORLD_MAX.z + 150);
		mDirection = mDestination - mSceneNode->getPosition();
		mDistance = mDirection.normalise();

	} else {
		mSceneNode->translate(mDirection * moveSpeed);
		mDistance -= moveSpeed;
	}

	return true;
}